//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using OpenLS.Core.Serialization;
using OpenLS.Spreadsheet.Data;

namespace OpenLS.Spreadsheet.Pivot
{
    internal class PivotTableError : PivotTableValue
    {
        private readonly List<Index> _x = new List<Index>();
        private Boolean _b;
        private string _bc;
        private string _c;
        private UInt32? _cp;
        private Boolean? _f;
        private string _fc;
        private Boolean _i;
        private UInt32? _in;
        private Boolean _st;
        private Tuples _tpls;
        private Boolean? _u;
        private Boolean _un;
        private string _v;
        internal const string xmlName = "e";

        #region IOfficeXmlSerializable Members

        public override void ReadXml(ReadContext context)
        {
            using (var c = context.Read(xmlName))
            {

                _v = c.GetString("v");
                _u = c.GetOptionalBoolean("u");
                _f = c.GetOptionalBoolean("f");
                _c = c.GetOptionalString("c");
                _cp = c.GetOptionalUInteger("cp");
                _in = c.GetOptionalUInteger("in");
                _bc = c.GetOptionalString("bc");
                _fc = c.GetOptionalString("fc");
                _i = c.GetOptionalBoolean("i", false);
                _un = c.GetOptionalBoolean("un", false);
                _st = c.GetOptionalBoolean("st", false);
                _b = c.GetOptionalBoolean("b", false);
                _tpls = c.ReadOptionalElement<Tuples>("tpls");
                _x.Clear();
                _x.AddRange(c.ReadOptionalWhile<Index>("x"));
            }
        }

        public override void WriteXml(WriteContext context)
        {
            using (var c = context.Write(xmlName))
            {
                c.SetString("v", _v);
                c.SetOptionalBoolean("u", _u);
                c.SetOptionalBoolean("f", _f);
                c.SetOptionalString("c", _c);
                c.SetOptionalUInteger("cp", _cp);
                c.SetOptionalUInteger("in", _in);
                c.SetOptionalString("bc", _bc);
                c.SetOptionalString("fc", _fc);
                c.SetOptionalBoolean("i", _i, false);
                c.SetOptionalBoolean("un", _un, false);
                c.SetOptionalBoolean("st", _st, false);
                c.SetOptionalBoolean("b", _b, false);
                c.WriteOptionalElement(_tpls);
                c.WriteElements(_x);
            }
        }

        public override object Value
        {
            get { return _v; }
            //\\ 
        }

        #endregion
    }
}